home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ahoy 1987 April
/
Ahoy_Magazine_87-04_1987_Double_L.d64
/
Fancy Factorials
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-10-26
|
1KB
|
33 lines
0 print"[147]":poke53280,0:poke53281,0:poke646,1
1 rem ==================================
2 rem commodares problem #36-1 :
3 rem fancy factorials
4 rem
90 rem----solution by matt shapiro------
100 h=100000:e=.0000001:i=0:j=0:k=1:c=0:p=0:n=0:dimf(3000):f(1)=1:input"n";n
110 for i=1 to n:for j=1 to k:p=i*f(j)+c:c=int(p/h+e):f(j)=p-h*c:next
120 if c then k=k+1 : f(k)=c : c=0
130 next:print mid$(str$(n),2)"!="mid$(str$(f(k)),2);
140 ifk>1thenforj=k-1to1step-1:printright$("0000"+mid$(str$(f(j)),2),5);:next
150 end
190 rem----solution by rob schultz------
200 input "n";n : m=1
210 for j=1 to n : m=m*j
220 if m>=10 then m=m/10 :e=e+1:goto 220
230 next : print m "e+" e
240 end
290 rem---solution by charles kluepfel--
300 input "n";n : print n"[157]! = ";
310 ln=log(n)*(n+.5)-n+log(2*(NULL))/2+1/(12*n)-1/(360*n*n*n)
320 ln=ln+1/(1260*n*n*n*n*n)-1/(1680*n*n*n*n*n*n*n)
330 if n<12 then print int(exp(ln)+.5) : goto 360
340 lg=ln/log(10) : ch=int(lg) :mn=lg-ch
350 print left$(str$(exp(mn*log(10)))+"0000000000",12-len(str$(ch)));"e"mid$(str$(ch),2)
360 end
390 rem------stirling's formula---------
400 input "specify n less than 34";n
410 nf=sqr(2*(NULL)*n)*(n/exp(1))^n
420 print n "! >" nf
430 print n "! <" nf*(1+1/(12*n-1))
440 end